<template>
  <a-spin :spinning="spinning">
    <iframe  :id="id" :src="url"  frameborder="0" style="width: 100%" scrolling="auto"></iframe>
  </a-spin>
</template>

<script>
  import { concatUrl,randomUUID, is} from "../../utils/util";
  import {appApiBaseUrl} from '../../config/constant.config';
  export default {
    name: "IframePageContent",
    data () {
      return {
        url: "",
        id:randomUUID(),
        spinning:false,
      }
    },
    mounted(){
      let height = document.body.clientHeight;
      let iframe = document.getElementById(this.id);
      iframe.style.height= (height -120)+"px";
      this.spinning = true;
      iframe.onload = ()=>{
        this.spinning = false;
      }
      this.createUrl();
    },
    methods: {
      createUrl () {
        let u = this.$route.path;
        console.log(u)
        if(u.indexOf('http')== 0){
          this.url = u;
        }else{
          this.url = concatUrl(appApiBaseUrl, u);
        }
        if(this.url.indexOf("?")>-1){
          if(this.url.endsWith("&")){
             this.url = this.url + "X-Access-Token="+ this.$store.getters.token();
          }else{
            this.url = this.url + "&X-Access-Token="+ this.$store.getters.token();
          }
        }else{
          this.url = this.url + "?X-Access-Token="+ this.$store.getters.token();
        }
      }
    }
  }
</script>

<style>
</style>